package com.bbx.taxi.client.Task;

import android.app.Activity;
import android.os.AsyncTask;

import com.bbx.androidapi.util.ToastUtil;
import com.bbx.api.sdk.model.official.passanger.Offciail_DevaluateInfoBuild;
import com.bbx.api.sdk.model.official.passanger.Return.Offciail_DevaluateInfo;
import com.bbx.api.sdk.net.base.JsonBuild;
import com.bbx.api.sdk.net.official.passanger.Offciail_DevaluateInfoNet;
import com.bbx.taxi.client.Task.BaseAsyncTask;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.official.R;
/** 
 * @Path com.bbx.taxi.client.Task.MyDevaluateInfo.java
 * @Author 严旭文
 * @Date 2016-2-22 上午10:41:06
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 * 订单评价信息
 */
public class MyOrderEvaluateInfoTask {
	public static int STATUS_SUCCESS=0;
	public static int STATUS_FAIL=-1;
	private Activity context;
	public static MyOrderEvaluateInfoTask instance;
	public OrderEvaluateInfoTask mOrderEvaluateTask;
	public interface OnEvaluateInfoListener {
		/**
		 *status 0为成功
		 */
		public void onEvaluateInfo(int status,Offciail_DevaluateInfo.Info info);
	}

	static OnEvaluateInfoListener mOnEvaluateInfoListener = null;

	public static void setOnEvaluateInfoListener(OnEvaluateInfoListener l) {
		mOnEvaluateInfoListener = l;
	}
	public static MyOrderEvaluateInfoTask getInstance(Activity context,String order_id) {
		instance = new MyOrderEvaluateInfoTask(context,order_id);
		return instance;
	}
	public MyOrderEvaluateInfoTask(Activity context,String order_id) {
		this.context = context;
		getOperate(order_id);
	}
	/**
	 * 订单评价
	 */
	public void getOperate(String  order_id) {
		Offciail_DevaluateInfoBuild info=new Offciail_DevaluateInfoBuild(context);
		info.order_id=order_id;
		info.passenger_id=MyApplication.getInstance().getUid();
		mOrderEvaluateTask = new OrderEvaluateInfoTask(context, info);
		mOrderEvaluateTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}
	private class OrderEvaluateInfoTask extends BaseAsyncTask {

		private Offciail_DevaluateInfoBuild info;

		public OrderEvaluateInfoTask(Activity context, Offciail_DevaluateInfoBuild info) {
			super(context,false);
			this.info = info;
		}

		@Override
		public void onSuccess(Object object) {
	       if(object!=null){
	    	   Offciail_DevaluateInfo mOffciail_DevaluateInfo=(Offciail_DevaluateInfo)object;
	    	   if(mOffciail_DevaluateInfo!=null&&mOffciail_DevaluateInfo.getInfo()!=null){
	    		   if (mOnEvaluateInfoListener != null) {
						mOnEvaluateInfoListener.onEvaluateInfo(STATUS_SUCCESS,mOffciail_DevaluateInfo.getInfo());
					} 
	    	   }else{
	    		   if (mOnEvaluateInfoListener != null) {
	   				mOnEvaluateInfoListener.onEvaluateInfo(STATUS_FAIL,null);
	   			}
	    	   }
	    	
	       }else{
    		   if (mOnEvaluateInfoListener != null) {
   				mOnEvaluateInfoListener.onEvaluateInfo(STATUS_FAIL,null);
   			}
    	   }
			
		}

		@Override
		public void onFailed(int status, String msg) {
			ToastUtil.showToast(context, R.string.no_network);
			if (mOnEvaluateInfoListener != null) {
				mOnEvaluateInfoListener.onEvaluateInfo(STATUS_FAIL,null);
			}
		}

		@Override
		protected Object doInBackground(Object... params) {
			// TODO Auto-generated method stub
			String json = new JsonBuild().setModel(info).getJson();
			return new Offciail_DevaluateInfoNet(context, json);
		}
	}

}
